// 引入路由组件
import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
//引入二级组件路由
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'
//路由配置信息
export default [{
        path: '/center',
        component: Center,
        meta: { Show: true },
        //二级路由/子路由
        children: [{
                path: 'myorder', //如果带/二级要全部写全路径，，不带/就行。
                component: MyOrder,
            },
            {
                path: 'grouporder',
                component: GroupOrder
            },
            {
                path: '/center', //重定向，一打开center就重定向到我的订单这里。
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        meta: { Show: true }
    },
    {
        path: '/pay',
        component: Pay,
        meta: { Show: true },
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {
                next()
            } else {
                next(false)
            }
        }
    },
    {
        path: '/trade',
        component: Trade,
        meta: { Show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //去交易页面，必须是从购物车过来
            if (from.path == '/shopcart') {
                next()
            } else {
                //其他路由组件而来的，停留在当前。。路由中断。
                next(false)
            }
        }
    },
    {
        path: '/shopcart',
        component: ShopCart,
        meta: { Show: true }
    },
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: AddCartSuccess,
        meta: { show: true }
    },
    {
        path: '/detail/:skuid', //当点击商品的图片的时候，跳转到对应的页面。。在路由跳转的时候需要带上产品的ID给详情页面。
        component: Detail,
        mata: { show: true }
    },
    {
        path: '/home',
        component: Home,
        meta: { show: true }
    },
    {
        path: '/search/:keyword?',
        component: Search,
        meta: { show: true },
        name: 'search'

    },
    {
        path: '/login',
        component: Login,
        meta: { show: false }

    },
    {
        path: '/register',
        component: Register,
        meta: { show: false }

    },
    {
        // 重定向，项目跑起来，立马定位到首页。
        path: '*',
        redirect: '/home'
    },

]